/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package lbim.server.main;

/**
 *
 * @author Jestan
 */
import java.util.Collection;
import java.util.Collections;
import org.apache.mina.core.service.IoHandlerAdapter;
import org.apache.mina.core.session.IdleStatus;
import org.apache.mina.core.session.IoSession;

public class HttpServerHandler extends IoHandlerAdapter {

    @Override
    public void sessionOpened(IoSession session) {
        // set idle time to 60 seconds
        session.getConfig().setIdleTime(IdleStatus.BOTH_IDLE, 60);
    }

    @Override
    public void messageReceived(IoSession session, Object message) {
        // Check that we can service the request context
        HttpRequestMessage request = (HttpRequestMessage) message;
        MessageHandler messageHandler = new MessageHandler();
        messageHandler.handleRequest(session, request);
    }

    @Override
    public void sessionIdle(IoSession session, IdleStatus status) {
    }

    @Override
    public void exceptionCaught(IoSession session, Throwable cause) {
    }

    public int getNumberOfUsers() {
        return LocateIMServer.currentUsers.size();
    }

    public Collection<String> getUserNames() {
        return LocateIMServer.currentUsers.values();
    }
}
